class Solution {
public:
    int totalMoney(int n) {
        int a = n / 7, b = n % 7;
        int res = (4 + 4 + a - 1) * a / 2 * 7;
        for (int i = 1; i <= b; i++) res += i + a;
        return res;
    }
};